//Genreting class to hide large images
var initThumbs = function(){
	var galImage= getElementsByClass("showme", document.getElementById("image-frame"));
	
	for(i=0; i<galImage.length; i++){
		if(i>0){
			if(hasClass(galImage[i], "showme")){
				removeClass(galImage[i], "showme");
				addClass(galImage[i], "hideme");
			}
		}
	}
	
	
	//Make thumb clickable
	
	
	var thumbImage= document.getElementById("image-list").getElementsByTagName("a");
	
	for(i=0;  i<thumbImage.length; i++){
		addEvent(thumbImage[i], 'click', showCurrent);
		addClass(thumbImage[i], "clickable");
	}
	


	
	//Make Arrows
	
	var showNext = function(){
		var currPreview= getElementsByClass("image-preview", document.getElementById("image-frame"));
	
		for(i=0; i<currPreview.length; i++){
			if(hasClass(currPreview[i], "showme")){
				if((i+1) < currPreview.length){
					removeClass(currPreview[i], "showme");
					addClass(currPreview[i], "hideme");
					var addClImage = i+1;
				}
			}
		}
		
		if(addClImage < currPreview.length){
			removeClass(currPreview[addClImage], "hideme");
			addClass(currPreview[addClImage], "showme");
		}
	}
	
	var showPrev = function(){
		var currPreview= getElementsByClass("image-preview", document.getElementById("image-frame"));
	
		for(i=0; i<currPreview.length; i++){
			if(hasClass(currPreview[i], "showme")){
				if((i-1) >= 0){
					removeClass(currPreview[i], "showme");
					addClass(currPreview[i], "hideme");
					var addClImage = i-1;
				}
			}
		}
		
		if(addClImage >= 0){
			removeClass(currPreview[addClImage], "hideme");
			addClass(currPreview[addClImage], "showme");
		}
	}
	
	addEvent(document.getElementById("arrow-left"), 'click', showPrev);
	addEvent(document.getElementById("arrow-right"), 'click', showNext);
}

var showCurrent = function(){
	var currVisible= getElementsByClass("showme", document.getElementById("image-frame"));
	//disable current
	removeClass(currVisible[0], "showme");
	addClass(currVisible[0], "hideme");
	
	//enable needed
	var enableMe = document.getElementById("large-" + this.id).parentNode;
	removeClass(enableMe, "hideme");
	addClass(enableMe, "showme");
}


//Generate Buy Link
var initBuy = function(buyclass, container){
	var buyButtons = getElementsByClass(buyclass, document.getElementById(container));
		for(i=0; i<buyButtons.length; i++){
			addEvent(buyButtons[i], "click", addToCart);
	}
}

var addToCart = function(){
	event.preventDefault();
	alert(this);
	return false;
}